import { request } from './request'
import { getCookie } from './cookie'

export function testCommonRequestFunc (url, type, requestBody) {
    // testRequest.defaults.headers.common['authorization'] = getCookie('login_tokens')
    return request({
        'url': url,
        'method': type,
        // 'Content-Type': 'application/json;charset=utf-8',
        'Content-Type': 'application/x-www-form-urlencoded',
        // 'data': JSON.stringify(requestBody || {})
        'data': type === 'post' ? requestBody : {},
        'params': type === 'get' ? requestBody : {}
    })
}

export function commonRequestFunc(url, requestBody, type = 'post') {
    // testRequest.defaults.headers.common['authorization'] = getCookie('login_tokens');
    return request({
        'url': url,
        'method': type,
        // 'Content-Type': 'application/json;charset=utf-8',
        'Content-Type': 'application/x-www-form-urlencoded',
        // 'data': JSON.stringify(requestBody || {})
        'data': type === 'post' ? requestBody : {},
        'params': type === 'get' ? requestBody : {}
    })
}

export function zcsCommonRequestFunc (apiKey, requestBody, type = 'post') {
    zcsRequest.defaults.headers.common['api_key'] = apiKey
    zcsRequest.defaults.headers.common['authorization'] = getCookie('login_tokens')
    return zcsRequest({
        'url': '/snapshot_api',
        'method': type,
        'Content-Type': 'application/json;charset=utf-8',
        'data': JSON.stringify(requestBody || {})
    })
}

export function getAuthorityCode (requestBody) {
    request.defaults.headers.common['api_key'] = 'SMC_OPERATE_HOME_08'
    request.defaults.headers.common['authorization'] = getCookie('login_tokens')
    return request({
        'url': '/snapshot_api',
        'method': 'post',
        'Content-Type': 'application/json;charset=utf-8',
        'data': JSON.stringify(requestBody)
    })
}

export function yyglLogin (requestBody) {
    request.defaults.headers.common['api_key'] = 'COP_MANAGE_HOME_01'
    // request.defaults.headers.common['authorization'] = getCookie('login_tokens')
    return request({
        'url': '/snapshot_api',
        'method': 'post',
        'Content-Type': 'application/json;charset=utf-8',
        'data': JSON.stringify(requestBody)
    })
}

export function loginRequestFunc (requestBody) {
    request.defaults.headers.common['api_key'] = 'COP_MANAGE_HOME_01'
    // request.defaults.headers.common['authorization'] = getCookie('login_tokens')
    return request({
        'url': '/snapshot_api',
        'method': 'post',
        'Content-Type': 'application/json;charset=utf-8',
        'data': JSON.stringify(requestBody)
    })
}

export function adminRequestFunc () {
    request.defaults.headers.common['api_key'] = 'COP_MANAGE_HOME_01'
    // request.defaults.headers.common['authorization'] = getCookie('login_tokens')
    return request({
        'url': '/snapshot_api',
        'method': 'post',
        'Content-Type': 'application/json;charset=utf-8',
        'data': JSON.stringify(requestBody)
    })
}
